<?php


namespace app\index\model;


use think\Db;
use think\Model;

class Collection extends Model
{
    /**
     * 个人页获取用户收藏职位信息
     * ywh开发
     *
     * @param $human
     * @param $currPage
     * @return \think\db\Query[]|\think\Paginator
     * @throws \think\exception\DbException
     */
    public function getCollAttr($human,$currPage = 1){
        return Db::table('collection')
            ->alias('coll')
            ->join(['official' => 'off'],'off.official_id = coll.official_id')
            ->join(['company' => 'company'],'company.company_id = off.company_id')
            ->join(['user' => 'user'],'off.user_id = user.user_id')
            ->join(['cotype' => 'type'],'type.company_id = off.company_id')
            ->field(['off.official','company.company_area',"off.job_money",'off.requirement','off.education'])
            ->field(['company.company_name','type.type'])
            ->field(['user.header','user.username','user.position'])
            ->where(['coll.user_id'       =>      $human, 'coll.is_delete'    =>      0])
            ->paginate(5,false,['page' => $currPage]);
    }

    /**
     * 个人页删除收藏
     * ywh开发
     *
     * @param $human
     * @param $data
     * @return Collection
     */
    public function deleteColl($human,$data){
        return $this
            ->alias('coll')
            ->join(['official' => 'off'],'off.official_id = coll.official_id')
            ->where(['coll.user_id' => $human , 'off.official' => $data['offName']])
            ->update(['coll.is_delete' => $data['is_delete']]);
    }

}